from langgraph.graph import Graph

# 1.先定义节点的功能(逻辑)
def func_1(input_1):
    return f"{input_1} hey"

def func_2(input_2):
    return f"{input_2} hello"

# 2.构建图
workflow = Graph()
# 添加节点
workflow.add_node("node_1", func_1)
workflow.add_node("node_2", func_2)
# 添加边
workflow.add_edge("node_1", "node_2")

# 定义入口节点和出口节点
workflow.set_entry_point("node_1")
workflow.set_finish_point("node_2")

# 3.对图进行编译
app = workflow.compile()
# 调用方式
# res = app.invoke("user input some word")
# print(res)
for output in app.stream("user input some word"):
    for k,v in output.items():
        print(f"{k=}, {v=}")